/*
 * Copyright © 2018 organization baomidou
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jugheadzhou.aop.advisor;

import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 定时任务异常拦截器
 *
 * @author jugheadzhou
 */
@Slf4j
public class TaskExceptionAnnotationInterceptor implements MethodInterceptor {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        String name = invocation.getThis().getClass() + "#" +invocation.getMethod().getName();
        try {
            log.info("定时任务[{}]开始执行", name);
            return invocation.proceed();
        } catch (Exception e) {
            log.error("定时任务[{}]发生未知异常：", name, e);
        }
        return null;
    }

}
